home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------------------
-
- Program: CPlusTESample 2.0AE
- File: List.h
-
- by Andrew Shebanow
- of Apple Macintosh Developer Technical Support
- with modifications by Eric Berdahl
-
- Copyright © 1989-1990 Apple Computer, Inc.
- Copyright © 1992 Eric Berdahl
- All rights reserved.
-
- ------------------------------------------------------------------------------------------*/
-
- #ifndef __LIST__
- #define __LIST__
-
- typedef void Object;
-
- // ObjectHandle is an Handle full of object pointers,
- // which we use as an array
- // We do two typedefs here to make that a
- // bit easier to read, since:
- // typedef void*** ObjectHandle;
- // is just too wierd.
- typedef Object* ObjectRef;
- typedef ObjectRef** ObjectHandle;
-
- class TList {
- public:
- TList();
-
- virtual void InsertFirst(Object* obj);
- virtual void InsertLast(Object* obj);
-
- virtual void MoveToFront(Object* obj);
- virtual void MoveToBack(Object* obj);
- virtual void MoveFront(Object* obj);
- virtual void MoveBack(Object* obj);
-
- virtual void Remove(Object* obj);
- virtual void RemoveAll();
- virtual void Delete(Object* obj);
- virtual void DeleteAll();
-
- virtual short Count() const;
-
- protected:
- virtual Object* At(short idx) const;
- virtual short FindIdx(Object* obj);
-
- short fNumObjs; // the number of elements in the list
-
- private:
- friend class TListIterator;
-
- ObjectHandle fObjects;
- };
-
- // Our inline methods - we do these so often, and they are so small,
- // that we make them inlines
-
- inline short TList::Count() const
- {
- return fNumObjs;
- }
-
- class TListIterator {
- public:
- TListIterator(const TList* ls);
- virtual Object* Next();
- virtual Object* Prev();
- virtual Object* First();
- virtual Object* Last();
-
- private:
- const TList* fList;
- short fIdx;
- };
-
- inline Object* TListIterator::Next()
- {
- return fList->At(++fIdx);
- }
-
- inline Object* TListIterator::Prev()
- {
- return fList->At(--fIdx);
- }
-
- inline Object* TListIterator::First()
- {
- fIdx = 0;
- return fList->At(fIdx);
- }
-
- inline Object* TListIterator::Last()
- {
- fIdx = fList->Count() - 1;
- return fList->At(fIdx);
- }
-
- #endif
-